# ===== Build stage =====
FROM maven:3.9.6-eclipse-temurin-17 AS build
WORKDIR /workspace
COPY pom.xml .
# 提前配置 Maven 镜像/仓库
COPY build/maven/settings.xml /root/.m2/settings.xml
# 使用 BuildKit 缓存加速 go-offline（需 DOCKER_BUILDKIT=1）
RUN --mount=type=cache,target=/root/.m2 mvn -B -e -DskipTests dependency:go-offline
COPY src ./src
# 使用缓存加速打包
RUN --mount=type=cache,target=/root/.m2 mvn -q -DskipTests package

# ===== Run stage =====
FROM eclipse-temurin:17-jre
ENV JAVA_OPTS="-Xms256m -Xmx512m"
WORKDIR /app
COPY --from=build /workspace/target/smart-parking-0.0.1-SNAPSHOT.jar app.jar
EXPOSE 8080
ENTRYPOINT ["sh","-c","java $JAVA_OPTS -jar app.jar --spring.profiles.active=${SPRING_PROFILES_ACTIVE:-default}"]


